// 导入模块
const api = require('../../api/api')
Page({
  data: {
    types: [] //所有分类
  },
  onReady: function () {
    this.loadHotFilms();
    this.loadLatesFilms();
    this.loadFreeFilms();
    this.loadTvFilms();
    this.loadVarietyShowFilms();
  },
  // 加载影院热映
  async loadHotFilms() {
    // api.loadHotFilms({
    //   start: 0,
    //   count: 6
    // }).then(data => {
    //   let type = {
    //     title: data.subject_collection.name,
    //     list: data.subject_collection_items
    //   }
    //   this.setData({
    //     'types[0]': type
    //   })
    // })
    const data = await api.loadHotFilms({
      start: 0,
      count: 6
    })
    let type = {
      title: data.subject_collection.name,
      list: data.subject_collection_items,
      method: data.method,
    }
    this.setData({
      'types[0]': type
    })
  },
  // 加载近期热门电影
  loadLatesFilms() {
    api.loadLatesFilms({
      start: 0,
      count: 6
    }).then(data => {
      let type = {
        title: data.subject_collection.name,
        list: data.subject_collection_items,
        method: data.method,
      }
      this.setData({
        'types[1]': type
      })
    })
  },
  // 加载免费在线观看的新片
  loadFreeFilms() {
    api.loadFreeFilms({
      start: 0,
      count: 6
    }).then(data => {
      let type = {
        title: data.subject_collection.name,
        list: data.subject_collection_items,
        method: data.method,
      }
      this.setData({
        'types[2]': type
      })
    })
  },
  // 电视剧
  loadTvFilms() {
    api.loadTvFilms({
      start: 0,
      count: 6
    }).then(data => {
      let type = {
        title: data.subject_collection.name,
        list: data.subject_collection_items,
        method: data.method,
      }
      this.setData({
        'types[3]': type
      })
    })
  },
  //综艺
  loadVarietyShowFilms() {
    api.loadVarietyShowFilms({
      start: 0,
      count: 6
    }).then(data => {
      let type = {
        title: data.subject_collection.name,
        list: data.subject_collection_items,
        method: data.method,
      }
      this.setData({
        'types[4]': type
      })
    })
  },
  // 点击跳转到搜索页面
  goSearch() {
    wx.navigateTo({
      url: '/pages/search/search',
    })
  }


})